#include<bits/stdc++.h>

using namespace std;
const int N=1e5+2;

int T,n,m,L,V,cnt,ans,maxn;
int d[N],v[N],a[N],p[N],vis[N];

bool cmp(int aa,int bb)
{
    return aa<bb;
}

double dis(int v,int aa)
{
    return (V^2-v^2)*1.0/(aa*2.0);
}

void checkl(double st,double ed)
{
    if(st>=ed) return;
    int l=1,r=n;
    while(l<r)
    {
        int mid=(l+r)/2;
        if(p[mid]<st) l=mid+1;
        else r=mid;
    }//dayudengyu
    int stt=l;

    l=1;r=n;
    while(l<r)
    {
        int mid=(l+r+1)/2;
        if(p[mid]<=st) l=mid-1;
        else r=mid-1;
    }//xiaoyu
    int edd=l+1;

    int flag=0;

    //cout<<stt<<" "<<edd<<"\n";
    for(int i=stt;i<=edd;i++) vis[i]++,flag=1;
    if(flag)
    {
        cnt++;
        //cout<<st<<" "<<ed<<"\n";
        }

}

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    for(int qqq=1;qqq<=T;qqq++)
    {
        cnt=0;ans=0;maxn=-1;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++) cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++) cin>>p[i],maxn=max(p[i],maxn);
        //sort(p+1,p+1+m);

        for(int i=1;i<=n;i++)
        {
            if(a[i]==0)
            {

                if(v[i]>V&&d[i]<=maxn)
                {
                    cnt++;

                    //for(int i=1;i<=n;i++) if(p[i]>=d[i]) vis[i]++;
                }
            }
        }


        //for(int i=1;i<=n;i++) maxx=max(vis[i],maxx);
        //for(int i=1;i<=n;i++) if(vis[i]==maxx) ans++;
        cout<<cnt<<" "<<n-1<<"\n";
    }
    return 0;
}
